package com.pj.ca.util;

import com.pj.ca.bc.ProviderInstance;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.crypto.Cipher;
import java.security.Security;
import java.security.Signature;

/**
 * 描述：
 *
 * @author pengjun
 * @date 2021/11/3 11:06
 */
public class AsymmetricalUtil {
    static {
        Security.addProvider(ProviderInstance.getBCProvider());
    }

    /**
     * cipher 获取
     * @param algorithm
     * @return
     * @throws Exception
     */
    public static Cipher getCipherInstance(String algorithm) throws Exception {
        Cipher cipher = Cipher.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);
        return cipher;
    }

    /**
     * cipher 获取
     * @param algorithm
     * @return
     * @throws Exception
     */
    public static Signature getSignatureInstance(String algorithm) throws Exception {
        Signature signature=Signature.getInstance(algorithm,BouncyCastleProvider.PROVIDER_NAME);
        return signature;
    }
}
